package functions.ems_claim;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.slf4j.LoggerFactory;
import com.beans.PayPlanLineBean;
import com.crc.mam.BaseCase;
import coms.Constants;
import coms.JSONToBean;
import coms.TestDateString;
import frame.HttpHelper;

public class ClaimPay extends BaseCase{
	private org.slf4j.Logger logger = LoggerFactory.getLogger(ClaimPay.class);


	/**
	 * 查询还款计划
	 */
	public PayPlanLineBean queryClaimPayPlan(String claimId) {
		logger.info(" 查询还款计划------- start -------------------");
		PayPlanLineBean payPlanLineBean = null;
		String params = "{\"claimId\":"+claimId+"}";
    	String url = Constants.QUERY_CLAIM_PAY_PLAN_URL;
    	try {
			result = HttpHelper.post(params, url);
			status = HttpHelper.isOk;
			logger.info("queryClaimPayPlan--------"+ result);
			if(status) {
			  try {
			    JSONArray array = new JSONArray(result);
			    JSONObject object = array.getJSONObject(0);
			    payPlanLineBean = JSONToBean.parseJson2Object(PayPlanLineBean.class, object.toString());
			    logger.info(payPlanLineBean.toString());
			    remark = payPlanLineBean.toString();
			  }catch(JSONException e) {
			    e.printStackTrace();
			    remark = "JSON解析错误";
			  }
			}else {
			  try {
			    JSONObject object = new JSONObject(result);
			    remark = object.getString("message");
			  }catch(JSONException e) {
			    remark = "JSON解析错误";
			  }
			  
			}
			
    	}catch(Exception e) {
    	    status = false;
    	    remark = "系统异常";
    		//e.printStackTrace();
    	}
    	logger.info(" 查询还款计划------- end -------------------");
    	return payPlanLineBean;
	}
	
	
	/**
	 * 插入还款计划
	 */
	public void claimPayPlanInser(String claimId) {
		logger.info(" 插入还款计划------- start -------------------");
		String param = "{\"payPlanId\":\"\",\"paymentType\":\"1\",\"dueDate\":\""+TestDateString.today()+"\",\"payAmount\":8888,\"isPay\":\"true\",\"remark\":\"test\",\"claimId\":"+claimId+"}";
		String url =  Constants.CLAIM_PAY_PLAN_INSERT_URL;
		try {
			 result = HttpHelper.post( param, url);
			 logger.info("claimPayPlanInser -- " + result);
		}catch(Exception e) {
			
		}
		
		logger.info(" 插入还款计划------- end -------------------");
	}
	

}
